package com.purplesoft.zettl.Listener;

import com.purplesoft.zettl.Activities.EditItem;
import com.purplesoft.zettl.Adapters.ItemListAdapter;
import com.purplesoft.zettl.DatabaseViews.VwItems;
import com.purplesoft.zettl.Provider.DatabaseContentProvider;

import android.content.Context;
import android.content.Intent;
import android.database.Cursor;
import android.view.GestureDetector.SimpleOnGestureListener;
import android.view.MotionEvent;
import android.widget.ListView;

public class ZettlGestureDetector extends SimpleOnGestureListener {

	private Cursor csVwPurchaseItems;
	private Context context;
	private ListView lvZettl;
	private ItemListAdapter laItems;
	
	public ZettlGestureDetector(Context context, ListView lvZettl) {
		this.context = context;
		this.lvZettl = lvZettl;
	}
	
	@Override
	public boolean onDoubleTap(MotionEvent e) {
		int position = lvZettl.pointToPosition((int) e.getX(), (int) e.getY());
		if (position != -1) {
			csVwPurchaseItems = context.getContentResolver().query(
					DatabaseContentProvider.VWPurchaseItems, null, null,
					null, null);
			laItems = new ItemListAdapter(context, csVwPurchaseItems);
			csVwPurchaseItems = (Cursor) laItems.getItem(position);
			int ciItem = csVwPurchaseItems.getColumnIndex(VwItems.Columns.Item);
			String item = csVwPurchaseItems.getString(ciItem);
			startEditItem(item);
		}
		return super.onDoubleTap(e);
	}

	
	@Override
	public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX,
			float velocityY) {
		// TODO Implementiere wisch nach Links oder Rechts
		return super.onFling(e1, e2, velocityX, velocityY);
	}

	public void startEditItem(String Item) {
		Intent intent = new Intent(context, EditItem.class);
		intent.putExtra("Item", Item);
		context.startActivity(intent);
	}

}
